'use strict';

const conn = require('../../libs/Conn');
const util = require('../../libs/Utils');

module.exports = async function (params) {
    let checkId = util.uuid();
    let ids = params.userIds.split(',');
    let userIdSql = ``;
    if(params.check_date === ''){
        params.check_date =null;
    }
    if(params.rectification_date === ''){
        params.rectification_date = null
    }
    let insertObj = {
            check_id:checkId,
            engineering_id:params.engineering_id,
            unit_type:params.unit_type,
            check_result:params.check_result,
            check_details:params.check_details,
            check_date:params.check_date,
            check_type:params.check_type,
            rectification_notice:params.rectification_notice,
            rectification_reply:params.rectification_reply,
            rectification_date:params.rectification_date,
            remarks:params.remarks
        };
    for(let id in ids){
        userIdSql += `INSERT INTO quality_check_user_middle (check_id,user_id) VALUES ('${checkId}', '${ids[id]}');`
    }
    let sql = 'INSERT INTO quality_check_file SET ?;'+userIdSql;
    await conn(sql, [insertObj]);
    return {success: true};
};